package com.atguigu.service_helpcenter.controller;

import com.atguigu.commonutils.R;
import com.atguigu.service_helpcenter.entity.HelpCenter;
import com.atguigu.service_helpcenter.entity.QueryVo;
import com.atguigu.service_helpcenter.mapper.HelpCenterMapper;
import com.atguigu.service_helpcenter.service.HelpCenterService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "帮助反馈管理(后台管理)")
@RestController
@RequestMapping("/helpServiceAdmin/")
public class HelpControllerAdmin {

    @Autowired
    private HelpCenterService helpCenterService;

    //1.获取所有的轮播图
    @ApiOperation("获取所有的帮助信息")
    @GetMapping("getAllHelpMessage")
    public R getAllBanners() {
        LambdaQueryWrapper<HelpCenter> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByAsc(HelpCenter::getModifiedTime);
        List<HelpCenter> allFrontBanner = helpCenterService.list(wrapper);
        return R.ok().data("getAllBanners", allFrontBanner);
    }

    //2.条件查询帮助信息带分页的方法
    @ApiOperation("分页条件查询帮助信息")
    @PostMapping("pageHelpCondition/{current}/{limit}")
    public R pageOrderCondition(@PathVariable("current") long current, @PathVariable("limit") long limit,
                                @RequestBody(required = false) QueryVo queryVo) {
        //创建page对象
        Page<HelpCenter> orderPage = helpCenterService.pageOrderCondition(current, limit, queryVo);
        long total = orderPage.getTotal();//总记录数
        List<HelpCenter> records = orderPage.getRecords(); //数据list集合
        return R.ok().data("total", total).data("rows", records);
    }


    //3.设置为已受理状态
    @ApiOperation("设置为已受理状态")
    @GetMapping("/setHelpOk/{helpId}")
    public R setHelpOk(@PathVariable("helpId") String helpId) {
        helpCenterService.setHelpOk(helpId);
        return R.ok();
    }
}

